﻿using Core.Info;
using Core.Log;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Core.Utility.Helper
{
    /// <summary>
    /// 调试助手类
    /// </summary>
    public class DebugHelper
    {
        /// <summary>
        /// 调试助手类构造函数
        /// </summary>
        public DebugHelper()
        {
            //Todo..
        }

        /// <summary>
        /// 调试助手类构造函数
        /// </summary>
        static DebugHelper()
        {

        }

        /// <summary>
        /// 调试钩子
        /// <code> DebugHelper.Hook( ()=>{}); </code>
        /// </summary>
        public static void Hook(Action action)
        {
            try
            {
                if (RunTimeInfo.IsDebug || RunTimeInfo.IsDevelopment)
                {
                    action.Invoke();
                }
            }
            catch (Exception ex)
            {
                AppTrace.Logger.LogError(ex,$" DebugHelper.Hook() 执行出现异常");
                //Console.WriteLine($"DebugHelper.Hook() 执行出现异常:{ex.DetailInfo()}");
            }
        }
    }
}
